using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using Spacejock;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;

namespace yWriter6
{
	public class clsPrintOneDayWorksheet
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintOneDayWorksheet()
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			try
			{
				num = Conversions.ToInteger(Interaction.InputBox("How many words do you want to write today?", "", "3000"));
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				ProjectData.ClearProjectError();
			}
			if (num == 0)
			{
				return;
			}
			try
			{
				num2 = Conversions.ToInteger(Interaction.InputBox("How many words per hour?", "", "500"));
			}
			catch (Exception ex3)
			{
				ProjectData.SetProjectError(ex3);
				Exception ex4 = ex3;
				ProjectData.ClearProjectError();
			}
			if (num2 == 0)
			{
				return;
			}
			if ((double)num / (double)num2 > 24.0)
			{
				clsShared.cLang.TransMsgBox("Words per hour x 24 is less than the words you want to write in one day. Please try again with a higher words per hour or a lower total words.");
				return;
			}
			DateTime time = default(DateTime);
			try
			{
				time = clsShared.cGetTime.GetTime(new DateTime(1, 1, 1, 9, 0, 0), WithSeconds: false, "Starting time");
			}
			catch (Exception ex5)
			{
				ProjectData.SetProjectError(ex5);
				Exception ex6 = ex5;
				ProjectData.ClearProjectError();
			}
			if (!((time.Hour == 0) & (time.Minute == 0)))
			{
				clsShared.cSubs.BusyMouse();
				try
				{
					clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "One day writing worksheet");
					clsReport.AddTitle();
					clsReport.AddBR(2);
					clsReport.SetTableBorder(1);
					clsReport.OpenTable("cellpadding=5");
					clsReport.OpenRow();
					clsReport.AddCell("End Time");
					clsReport.AddCell("New words written");
					clsReport.AddCell("Running Total");
					clsReport.AddCell("Progressive Target");
					clsReport.AddCell("Net +/-");
					clsReport.CloseRow();
					DateTime dateTime = time;
					do
					{
						dateTime = dateTime.AddHours(1.0);
						clsReport.OpenRow();
						clsReport.AddCell(Strings.Format(dateTime, "HH") + ":00");
						clsReport.AddCell("");
						clsReport.AddCell("");
						num3 += num2;
						clsReport.AddCell(Conversions.ToString(num3));
						clsReport.AddCell("");
						clsReport.CloseRow();
					}
					while (num3 <= num);
					clsReport.CloseTable();
					clsReport.AddFooter(App.Title);
					clsReport.Show();
					PrintProgressEvent?.Invoke("Printing Complete");
				}
				catch (Exception ex7)
				{
					ProjectData.SetProjectError(ex7);
					Exception ex8 = ex7;
					clsShared.cLog.AddAction(ex8, MethodBase.GetCurrentMethod());
					ProjectData.ClearProjectError();
				}
				clsShared.cSubs.NormalMouse();
			}
		}
	}
}
